import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {		//全局变量定义处
		hasLogin: false,		//用户是否登录
		userInfo: {},			//用于存放用户账号数据
	},
	mutations: {
		login(state, userInfo) {
			state.hasLogin = true;
			state.userInfo = userInfo;
			uni.setStorage({//缓存用户登陆状态
			    key: 'userInfo',  
			    data: userInfo  
			});
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({  
		        key: 'userInfo'  
		    })
		}
	},
	actions: {}
})

export default store
